home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / pcw.zip / RANDWND.C < prev    next >
C/C++ Source or Header  |  1991-05-12  |  3KB  |  56 lines

  1. /***********************************************************/
  2. /* File Id.                  Randwnd.C                     */
  3. /* Author.                   Stan Milam.                   */
  4. /* Date Written.             09 Sep 89                     */
  5. /*                                                         */
  6. /* Comments:  Generate random windows around the screen    */
  7. /* then move them around randomly until a key is pressed.  */
  8. /* Notice there is no code in this program to remove the   */
  9. /* windows:  We let the autoexit do it for us.             */
  10. /***********************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <conio.h>
  15. #include <time.h>
  16. #include <pcwproto.h>
  17.  
  18. #define MAXWND 20                      /* Max windows */
  19. #define random(m) (rand() % (m))       /* Random number generator macro */
  20. #define egacolor (_adaptor > CGA && _monitor == COLOR)
  21.  
  22. int main(void) {
  23.  
  24.    WNDPTR *wnd[MAXWND];                /* Array of window */
  25.    int    fclr, bclr, r1, r2, c1, c2;  /* Colors & location */
  26.    int    mxr, mxc, lcv;               /* Scratch Integers */
  27.    long   timer;                       /* For seeding random numbers */
  28.  
  29.    fload(0,8);                          /* Load 8x8 font */
  30.    srand(time(&timer));                 /* Seed random number generator */
  31.    chk_video_state(&mxr, &mxc);         /* Get max rows & cols */
  32.    for (lcv = 0; lcv < MAXWND; lcv++) { /* Put out MAXWND windows */
  33.      r1 = random(mxr-6)+1;r2 = r1 + 6;  /* Generate rows */
  34.      c1 = random(mxc-20)+1;c2 = c1 + 20;/* Generate columns */
  35.      do {                               /* Make sure the background */
  36.        fclr = random(15) + 1;           /*    and foreground are not equal */
  37.        bclr = random(7)  + 1;
  38.      } while (fclr == bclr);
  39.      bordercolor(fclr, bclr);           /* Set border color */
  40.      do {                               /* Make sure background color and */
  41.        fclr = random(16);               /*    and foreground != */
  42.        bclr = random(8);
  43.      } while (fclr == bclr);
  44.      wnd[lcv] = wframe(r1, c1, r2, c2, fclr, bclr);
  45.      wprintf(wnd[lcv], 3,CENTER,"Window %02d",lcv+1);
  46.    }
  47.    while (!kbhit()) {                   /* Do until key is pressed */
  48.        r1 = random(mxr - 6) + 1;        /* Randomly select row & column */
  49.        c1 = random(mxc - 20) + 1;
  50.        lcv= random(MAXWND);             /* Randomly select a window */
  51.        wndmove(wnd[lcv], r1, c1);       /* Move it */
  52.    } getch();                           /* Remove char from keyboard buffer */
  53.    fload(0, (_adaptor == EGA) ? 14 : 16);
  54.    return(0);
  55. }
  56.